# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>

pkgname=rocsolver
pkgver=5.7.1
pkgrel=1
pkgdesc='Subset of LAPACK functionality on the ROCm platform'
arch=('loong64' 'x86_64')
url='https://rocsolver.readthedocs.io/en/latest/'
license=('BSD 2-Clause')
depends=('hip' 'rocblas' 'rocsparse')
makedepends=('rocm-cmake' 'python-pyaml' 'fmt')
_git='https://github.com/ROCmSoftwarePlatform/rocSOLVER'
source=("$pkgname-$pkgver.tar.gz::$_git/archive/rocm-$pkgver.tar.gz")
sha256sums=('83e0c137b8690dbeb2e85d9e25415d96bd06979f09f2b10b2aff8e4c9f833fa4')
options=(!lto !buildflags)
_dirname="$(basename "$_git")-$(basename "${source[0]}" .tar.gz)"

build() {
    # Compile source code for supported GPU archs in parallel
    export HIPCC_COMPILE_FLAGS_APPEND="-parallel-jobs=$(nproc)"
    export HIPCC_LINK_FLAGS_APPEND="-parallel-jobs=$(nproc)"
    # -fcf-protection is not supported by HIP, see
    # https://rocm.docs.amd.com/en/latest/reference/rocmcc/rocmcc.html#support-status-of-other-clang-options
    CXXFLAGS="${CXXFLAGS} -fcf-protection=none" \
    cmake \
      -Wno-dev \
      -B build \
      -S "$_dirname" \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_CXX_COMPILER=/opt/rocm/bin/hipcc \
      -DCMAKE_INSTALL_PREFIX=/opt/rocm \
      -DROCSOLVER_EMBED_FMT=ON
    cmake --build build
}

package() {
    DESTDIR="$pkgdir" cmake --install build

    echo "/opt/rocm/$pkgname/lib" > "$pkgname.conf"
    install -Dm644 "$pkgname.conf" "$pkgdir/etc/ld.so.conf.d/$pkgname.conf"

    install -Dm644 "$_dirname/LICENSE.md" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
